package com.sl.au.controller;

import com.sl.au.entity.Account;
import com.sl.au.entity.ExdeContractBillAgingLedger;
import com.sl.au.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/ui/payAppData")
public class PayAppDataController extends BaseController {

	@Autowired
	ContractService contractService;
	@Autowired
	PaymentInitialService paymentInitialService;
	@Autowired
	PayPlanService payPlanService;
	@Autowired
	ExdeContractBillAgingLedgerService exdeContractBillAgingLedgerService;
	///移动端应收账明细数据
	@RequestMapping(value = "/{contractId}/getData", method = RequestMethod.GET)
	public Map<String, Object> getPage(@PathVariable String contractId) {
		Map<String, Object> map = new HashMap<String, Object>();
		Map<String, Object> map1 = new HashMap<String, Object>();
		List<Object> data=null;
		float[] paidSum=paymentInitialService.getPayRegistRepository().getPaySum(contractId);
		if(paidSum.length==0){
			map1.put("paidSum",0);
		}
		else {
			float paidSums = 0;
			for (int i = 0; i < paidSum.length; i++) {
				paidSums = paidSums + paidSum[i];
			}
		map1.put("paidSum",paidSums);
		}
		float[] paymentSum=paymentInitialService.getPaymentRegistRepository().getPaymentSum(contractId);
		if(paymentSum.length==0){
			map1.put("paymentSum",0);
		}
		else {
			float paymentSums = 0;
			for (int i = 0; i < paymentSum.length; i++) {
				paymentSums = paymentSums + paymentSum[i];
			}
			map1.put("paymentSum", paymentSums);
		}
		ExdeContractBillAgingLedger exdeContractBillAgingLedgers=exdeContractBillAgingLedgerService.findStatisticsById(contractId);
		map1.put("exdeContractBillAgingLedgers",exdeContractBillAgingLedgers);
		map.put("data",map1);
		return map;
	}
}
